﻿using System.Linq;
using System.Security.Principal;
using Interfaces.Models;

namespace Framework.Security
{
    public class EISSessionPrincipal : IPrincipal
    {
        private readonly EISSessionIdentity _identity; 
        
        public EISSessionPrincipal(ISession session)
        {
            _identity = new EISSessionIdentity(session);
        }
        
        public bool IsInRole(string role)
        {
           return _identity.Session.User.Roles.Any(x => x.Type.ToString().Equals(role));
        }

        public IIdentity Identity
        {
            get { return _identity; }
        }
    }
}
